/*
 *  JDiv - API for Multimedia Application
 *  http://jdiv.sourceforge.net 
 *  ------------------------------------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

package com.jdiv.internalClasses;

import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.jdiv.kernel.JDivSystem;

public class JDivEffect extends JDivDisposable {
	
  public ParticleEffect effect;
  public boolean show;
  
  private boolean loadEffect;
  
  FileHandle fileEffect, dir;
  
  public JDivEffect( FileHandle fileEffect, FileHandle dir ){
	  loadEffect = false;
	  this.fileEffect = fileEffect;  
	  this.dir  = dir;
	  show = true;
	  
	  effect = new ParticleEffect();
	  
  }
  
  public void load(){  
	  
	  effect.load(fileEffect, dir); 
	  loadEffect = true;
	  
	  for( int i = 0; i < effect.getEmitters().size; i++ ){
	   Texture texture = effect.getEmitters().get(i).getSprite().getTexture();
	   
	   if( texture != null )
	    texture.setFilter(JDivSystem.jdivTextureFilter, JDivSystem.jdivTextureFilter);
	  }
  }
  
  public void dispose(){
	  
	  if( loadEffect )
	   effect.dispose();
	  
	  effect = null;
	  loadEffect = false;
  }
  
  public boolean isLoadEffect(){
	  return loadEffect;
  }
  
  public void setPosition( float x, float y ){
	  if( loadEffect ){
		  effect.setPosition(x, y);
	  }
  }
  
  public void start(){
	  if( loadEffect ) {
		  effect.start();
	  }
  }
  
}
